package com.netty.handler;

import com.alibaba.fastjson.JSONObject;
import com.netty.core.DefaultFuture;
import com.param.Response;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.json.JsonObjectDecoder;

public class ClientHandler extends SimpleChannelInboundHandler<String>{

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		Response response = null;
		if(msg.equals("ping"))
		{
			ctx.channel().writeAndFlush("ping"+"\r\n");
			return;
		}
		
		try
		{
			response = JSONObject.parseObject(msg, Response.class);
		}catch (Exception e) 
		{
			e.printStackTrace();
			System.out.println(msg);
		}
		
		DefaultFuture.recive(response);
	}

}
